package com.star.book.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.google.common.collect.Maps;
import com.star.book.entity.StarBook;
import com.star.book.mapper.StarBookMapper;
import com.star.book.service.IStarBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr Kong
 * @since 2020-10-04
 */
@Service
public class StarBookServiceImpl extends ServiceImpl<StarBookMapper, StarBook> implements IStarBookService {

    @Autowired
    private IStarBookService starBookService;

    @Override
    public StarBook selectStarBookByTime() {
        return baseMapper.selectStarBookByTime();
    }

    @Override
    public List<StarBook> selectStarBookByBookCount() {
        return baseMapper.selectStarBookByBookCount();
    }

    @Override
    public List<StarBook> findByPage(Integer id) {
        return baseMapper.findByPage(id);
    }

    @Override
    public Map<String, Object> starBookLog(Integer id) {
        Map<String, Object> starBookMap = Maps.newHashMap();
        List<StarBook> list = starBookService.list();
        int starBookTotalCount = list.size();
        Integer page ;
        if(starBookTotalCount == 0 || starBookTotalCount < 0){
            page = 0;
        }else{
            page = starBookTotalCount / 10;
            if(starBookTotalCount % 10 > 0){
                page=page+1;
            }
        }
        starBookMap.put("page",page);
        List<StarBook> byPage = baseMapper.findByPage(id);
        starBookMap.put("starBookByPage",byPage);
        return starBookMap;
    }

}
